package com.jzo2o.customer.controller.consumer;


import com.jzo2o.common.model.PageResult;
import com.jzo2o.common.model.Result;
import com.jzo2o.customer.model.dto.request.AddressBookPageQueryReqDTO;
import com.jzo2o.customer.model.dto.request.AddressBookUpsertReqDTO;
import com.jzo2o.customer.model.dto.response.AddressBookPageQueryResDTO;
import com.jzo2o.customer.service.IAddressBookService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户地址相关接口
 */
@RestController("AddressController")
@RequestMapping("/consumer/address-book")
@Api(tags = "用户端 - 用户地址相关接口")
public class AddressController {

    @Autowired
    private IAddressBookService addressBookService;

    /**
     * 新增地址
     * @param reqDTO
     * @return
     */
    @PostMapping
    public Boolean add(@RequestBody AddressBookUpsertReqDTO reqDTO){
       return addressBookService.add(reqDTO);

    }

    /**
     * 分页查询
     * @param
     * @return
     */
    @GetMapping("/page")
    public PageResult<AddressBookPageQueryResDTO> page(AddressBookPageQueryReqDTO reqDTO){
        PageResult<AddressBookPageQueryResDTO> result = addressBookService.pageFind(reqDTO);
        return result;
    }

    /**
     * 根据查询地址详情
     * @param
     * @return
     */
    @GetMapping("/{id}")
    public AddressBookPageQueryResDTO selectById(@PathVariable String id){
        AddressBookPageQueryResDTO address = addressBookService.selectById(id);
        return address;
    }


    /**
     *修改地址
     * @param reqDTO
     * @return
     */
    @PutMapping("/{id}")
    public Boolean updateAddress(@RequestBody AddressBookUpsertReqDTO reqDTO,@PathVariable String id){
        return addressBookService.updateAddress(reqDTO,id);

    }


    /**
     *批量删除地址
     * @param ids
     * @return
     */
    @DeleteMapping("/batch")
    public Boolean delete(@RequestBody String ids){
        return addressBookService.delete(ids);

    }


    /**
     *设置默认地址
     * @param
     * @return
     */
    @PutMapping("/default")
    public Boolean updateDefault(@RequestParam Integer flag,Long id){
        return addressBookService.updateDefault(flag,id);

    }

    /**
     * 获取默认接口
     * @param
     * @return
     */
    @GetMapping("/defaultAddress")
    public AddressBookPageQueryResDTO defaultAddress(){
        AddressBookPageQueryResDTO address = addressBookService.getDefaultAddress();
        return address;
    }




}
